/*
 * @Author: your name
 * @Description: 
 * @FilePath: /code/time/timer_manager.h
 */
#pragma once

#include "timer.h"

#include <queue>
#include <vector>
#include <unordered_map>

auto cmp = [](Timer* t1,Timer* t2){return t1->ExpiredTime() > t2->ExpiredTime();};
class TimerManager
{
public:
    using TimeEventCallback = std::function<void()>;
    TimerManager() = default;
    ~TimerManager() = default;
    int64_t AddTimer(int32_t repeatedtimes,int64_t interval,TimeEventCallback& callback);
    void RemoveTimer(int64_t id);
    void CheckAndHandle();
private:
    std::priority_queue<Timer*,std::vector<Timer*>,decltype(cmp)> timers_queue_{cmp};

    std::unordered_map<int64_t,Timer*> timer_mp_;
};